package cn.itrip.order.service;

import cn.itrip.dao.ItripImageMapper;
import cn.itrip.pojo.ItripImage;
import cn.itrip.vo.ItripImageVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ImageServiceImpl implements ImageService{
    @Resource
    private ItripImageMapper itripImageMapper;

    /**
     * 根据关联id查询图片列表
     * @param targetId
     * @return
     * @throws Exception
     */
    @Override
    public List<ItripImageVO> selectImgByTargetId(Long targetId) throws Exception {

        if(targetId == null){
            throw new Exception("参数错误");
        }

        Map map = new HashMap();
        map.put("targetId",targetId);
        map.put("type",2);

        List<ItripImage> list = itripImageMapper.getImageListByByTargetId(map);

        List<ItripImageVO> itripImageVOS = new ArrayList<>();
        ItripImageVO itripImageVO = null;
        for(ItripImage itripImage:list){
         itripImageVO = new ItripImageVO();

         itripImageVO.setImgUrl(itripImage.getImgurl());

         itripImageVO.setPosition(itripImage.getPosition());

         itripImageVOS.add(itripImageVO);

        }

        return itripImageVOS;
    }
}
